 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using CrystalCore;
using CrystalCore.Libs;

namespace CrystalCore.Mapping
{
    public abstract class FloorCell : CellBase
    {
        //Fields 
				
        //cTor
        public FloorCell(MazePosition position)
            : base(position)
        {
            this.CellPrimitive.Rescale(Globals.CellSize);
        }

        //Methods        
        protected override void RenderCell()
        {
            Matrix[] transforms = new Matrix[Resources.CubeFloorModel.Bones.Count];
            Resources.CubeFloorModel.CopyAbsoluteBoneTransformsTo(transforms);
            foreach (ModelMesh mesh in Resources.CubeFloorModel.Meshes)
            {
                foreach (Effect fx in mesh.Effects)
                {
                    fx.CurrentTechnique = fx.Techniques["CellShade"];

                    fx.Parameters["World"].SetValue(transforms[mesh.ParentBone.Index] * CellPrimitive.World);
                    fx.Parameters["View"].SetValue(ObjectHolder.GameCamera.View);
                    fx.Parameters["Projection"].SetValue(ObjectHolder.GameCamera.Projection);
                    
                    fx.Parameters["Texture"].SetValue(Resources.CubeFloorTexture);
                    fx.Parameters["CellColour"].SetValue(CrystalCoreConversions.ElementToColour(this.CellElement).ToVector4());
                    
                    fx.Parameters["Eye"].SetValue(ObjectHolder.GameCamera.CameraPosition);
                    fx.Parameters["SpecularColor"].SetValue(Color.White.ToVector4());

                    fx.Parameters["AmbientColor"].SetValue(Globals.AmbientLightColor.ToVector4());
                    fx.Parameters["AmbientLevel"].SetValue(Globals.AmbientLightLevel);

                    fx.Parameters["DiffuseDirection"].SetValue(Globals.DiffuseDirection);
                    fx.Parameters["DiffuseColour"].SetValue(Globals.DiffuseColour.ToVector4());
                    fx.Parameters["DiffuseIntensity"].SetValue(Globals.DiffuseLightLevel);
                }
                mesh.Draw();
            }
        }
    }
}